import { defineStore } from 'pinia'

export const useCommonStore = defineStore({
  id: 'pure-commonstore',
  state: () => ({
    projectStarUp: false,
    customBar: 0, // 手机状态栏和头部导航栏高度
    statusBar: 0, // 状态栏高度
  }),
  getters: {
    getMemberList: (state) => {
      return state.memberList
    },
    getStarUpState: (state) => {
      return state.projectStarUp
    },
  },
  actions: {
    getCustomBar() {
      uni.getSystemInfo({
        success: (e) => {
          // this.compareVersion(e.SDKVersion, '2.5.0')
          let statusBar = 0
          let customBar = 0

          // #ifdef MP
          statusBar = e.statusBarHeight
          customBar = e.statusBarHeight + 45
          if (e.platform === 'android') {
            customBar = e.statusBarHeight + 50
          }
          // #endif

          // #ifdef MP-WEIXIN
          statusBar = e.statusBarHeight
          // @ts-ignore
          const custom = wx.getMenuButtonBoundingClientRect()
          customBar = custom.bottom + custom.top - e.statusBarHeight
          // #endif

          // #ifdef MP-ALIPAY
          statusBar = e.statusBarHeight
          customBar = e.statusBarHeight + e.titleBarHeight
          // #endif

          // #ifdef APP-PLUS
          statusBar = e.statusBarHeight
          customBar = e.statusBarHeight + 45
          // #endif

          // #ifdef H5
          statusBar = 0
          customBar = e.statusBarHeight + 45
          // #endif

          this.statusBar = statusBar
          this.customBar = customBar
        },
      })
    },
    getProjectStarUp(data) {
      this.projectStarUp = data
    },
  },
})
